//
//  JYTBaseHeadView.m
//  JYT_IOS
//
//  Created by wolf －yuan on 16/11/13.
//  Copyright © 2016年 com.yuan. All rights reserved.
//

#import "JYTBaseHeadView.h"
@interface JYTBaseHeadView ()
{
    UIButton *leftBtn;
    UIButton *rightBtn;
    UILabel *titleLab;
}

@end


@implementation JYTBaseHeadView
- (instancetype)init
{
    self = [super init];
    
    if (self) {
        [self setBackgroundColor:[UIColor colorWithRed:131/255.0f green:182/255.0f blue:248/255.0f alpha:1]];
        
        leftBtn = [[UIButton alloc] init];
        [self addSubview:leftBtn];
        [leftBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
        //        [leftBtn setHidden:YES];
        [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [leftBtn addTarget:self action:@selector(clickSelfLeftButton) forControlEvents:UIControlEventTouchUpInside];
        [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top).with.offset(30);
            make.left.equalTo(self.mas_left).with.offset(15);
            make.width.mas_equalTo(40);
            make.bottom.equalTo(self.mas_bottom).with.offset(-6);
        }];
        
        
        rightBtn = [[UIButton alloc] init];
        [self addSubview:rightBtn];
        [rightBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
        [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [rightBtn addTarget:self action:@selector(clickSelfRightButton) forControlEvents:UIControlEventTouchUpInside];
        [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top).with.offset(20);
            make.right.equalTo(self.mas_right).with.offset(0);
            make.width.mas_equalTo(60);
            make.bottom.equalTo(self.mas_bottom).with.offset(0);
        }];
        
        
        titleLab = [[UILabel alloc] init];
        [titleLab setBackgroundColor:[UIColor clearColor]];
        [self addSubview:titleLab];
        [titleLab setTextAlignment:NSTextAlignmentCenter];
        [titleLab setTextColor:[UIColor whiteColor]];
        [titleLab setFont:[UIFont systemFontOfSize:17]];
        
        UIEdgeInsets tpadding = UIEdgeInsetsMake(20, 50, 0, 50);
        
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self).with.insets(tpadding);
        }];
    }
    
    return self;
}


- (void) setNavgationBarWithDic:(NSDictionary *)dic
{
    if (dic) {
        NSString *lftBtnBgImg = dic[@"lftBtnBgImg"];
        NSString *rhtBtnBgImg = dic[@"rhtBtnBgImg"];
        
        NSString *pageTitleStr = dic[@"pageTitle"];
        NSString *lftBtnTitle = dic[@"lftBtnTitle"];
        NSString *rhtBtnTitle = dic[@"rhtBtnTitle"];
        
        
        if (![lftBtnBgImg isEqualToString:@"no"]) {
           // [leftBtn setBackgroundImage:[UIImage imageNamed:lftBtnBgImg] forState:UIControlStateNormal];
            [leftBtn setImage:[UIImage imageNamed:lftBtnBgImg] forState:UIControlStateNormal];
        } else {
            [leftBtn setHidden:YES];
            [leftBtn setTitle:lftBtnTitle forState:UIControlStateNormal];
            
        }
        
        if ([rhtBtnTitle isEqualToString:@"no"] && [rhtBtnBgImg isEqualToString:@"no"]) {
            
            [rightBtn setBackgroundImage:[UIImage imageNamed:rhtBtnBgImg] forState:UIControlStateNormal];
            [rightBtn setHidden:YES];
            
        } else {
            
            if (![rhtBtnTitle isEqualToString:@"no"]) {
                [rightBtn setTitle:rhtBtnTitle forState:UIControlStateNormal];
                
            }
            
            if (![rhtBtnBgImg isEqualToString:@"no"]) {
                //[rightBtn setBackgroundImage:[UIImage imageNamed:rhtBtnBgImg] forState:UIControlStateNormal];
                [rightBtn setImage:[UIImage imageNamed:rhtBtnBgImg] forState:UIControlStateNormal];
            }
        }
        
        [titleLab setText:pageTitleStr];
    }
}


- (void)setIsNormalBar
{
    if (leftBtn) {
        [leftBtn setHidden:NO];
    }
}


- (void)setIsRootBar
{
    if (leftBtn) {
        [leftBtn setHidden:YES];
    }
    
    if (rightBtn) {
        [rightBtn setHidden:YES];
    }
}



- (void)setHiddenLeftBtn
{
    if (leftBtn) {
        [leftBtn setHidden:YES];
    }
}


- (void)setHiddenRightBtn
{
    if (leftBtn) {
        [rightBtn setHighlighted:YES];
    }
}


- (void) clickSelfLeftButton
{
    if (self.delegate) {
        [self.delegate clickLeftBtn];
    }
}


- (void) clickSelfRightButton
{
    if (self.delegate) {
        [self.delegate clickRightBtn];
    }
}

@end
